﻿using System.Net.Mail;

namespace AspNetInfo.Helpers
{
    public class EmailTestor
    {
        public static void SendEmail(string from, string to, string subject, string message, bool isBodyHtml, SmtpClient smtp)
        {
            var testEmail = new MailMessage(from, to) 
                {Subject = subject, Body = message, IsBodyHtml = isBodyHtml};
            smtp.Send(testEmail);
        }

        public static SmtpClient GetDefaultSmtp()
        {
            return new SmtpClient();
        }

        public static SmtpClient GetCustomSmtp(string host, int port,
            SmtpDeliveryMethod delivery, string pickupLocation, int timeout, bool enableSsl)
        {
            var smtp = GetDefaultSmtp();
            smtp.Host = host;
            smtp.Port = port;
            smtp.DeliveryMethod = delivery;
            smtp.PickupDirectoryLocation = pickupLocation;
            smtp.Timeout = timeout;
            smtp.EnableSsl = enableSsl;
            return smtp;
        }

        public static SmtpClient SetSmtpCredentials(SmtpClient smtp, string username, string password)
        {
            var smtpUser = new System.Net.NetworkCredential
                {UserName = username, Password = password};
            smtp.Credentials = smtpUser;

            return smtp;
        }
    }
}
